package com.jied.duodian.util;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * Description:
 *
 * @author LiJie
 * @date Created on 2020/11/5
 * WWW https://github.com/j6l
 */
@Component
public class SuId {

    static Snowflake snowflake = IdUtil.getSnowflake( 1, 1 );
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    /**
     * request获取username
     *
     * @param req
     * @return
     */
    public String getuserName(HttpServletRequest req) {
        String header = req.getHeader( "Authorization" ).substring( "Bearer ".length() );
        String username = jwtTokenUtil.getUsernameFromToken( header );
        return username;
    }


    public String getNewId() {
        return snowflake.nextIdStr();
    }

    public static void main(String[] args) {
        SuId id = new SuId();
        System.out.println( id.getuuid() );
    }

    public String getuuid() {
        String s = IdUtil.simpleUUID();
        return s;
    }
}
